﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Allscore;
using BaifudataPay.Applib;

namespace BaifudataPay
{
    public partial class BankPayIndex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string host_ip = "http://baifupay.34537.com/";

                out_orderNo.Value = DateTime.Now.ToString("yyyyMMddHHmmss");
                return_url.Value = host_ip + "returnRSA.aspx";
                notify_url.Value = host_ip + "notifyRSA.aspx";
                detail_url.Value = host_ip + "detail.aspx";
            }
            else
            {
                ////////////////////////////////////////////请求参数////////////////////////////////////////////

                //必填参数//
                //请与贵网站订单系统中的唯一订单号匹配

                string service = "directPay";

                string outOrderId = out_orderNo.Value.Trim();
                //外部帐户ID
                string outAcctId = out_AcctId.Value.Trim();
                string transAmt = out_transAmt.Value.Trim();

                string subject = out_subject.Value.Trim();
                string body = out_body.Value.Trim();
                string payMethod = pay_method.Value.Trim();
                string certType = cert_type.Value.Trim();
                string notifyUrl = notify_url.Value.Trim();
                string returnUrl = return_url.Value.Trim();
                string detailUrl = detail_url.Value.Trim();
                string channel = out_channel.Value.Trim();
                string signType = sign_type.Value.Trim();
                string merchantId = merchant_id.Value.Trim();
                string defaultBank = default_bank.Value.Trim();
                string cardAttr = card_attr.Value.Trim();





                ////////////////////////////////////////////////////////////////////////////////////////////////

                //把请求参数打包成数组
                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();

                /*
                sParaTemp.Add("outOrderId", outOrderId);  //外部交易号
                sParaTemp.Add("outAcctId", outAcctId);    //外部账户ID

                sParaTemp.Add("signType", signType);   //签名类型

                */
                //////


                sParaTemp.Add("service", service);
                sParaTemp.Add("merchantId", merchantId);
                //sParaTemp.put("terminalId", terminalId);
                //sParaTemp.put("outOrderId", outOrderId);
                sParaTemp.Add("transAmt", transAmt);


                sParaTemp.Add("outOrderId", outOrderId);


                sParaTemp.Add("subject", subject);
                sParaTemp.Add("body", body);
                //  		sParaTemp.put("name", name);
                //  		sParaTemp.put("id", certId);
                //  		sParaTemp.put("mobile", mobile);
                sParaTemp.Add("signType", signType);
                sParaTemp.Add("payMethod", payMethod);
                if (payMethod == "fastPay")
                {
                    sParaTemp.Add("cardType", certType);
                    sParaTemp.Add("outAcctId", outAcctId);
                }

                if (payMethod == "bankPay")
                {
                    sParaTemp.Add("defaultBank", defaultBank);
                    sParaTemp.Add("channel", channel);
                    sParaTemp.Add("cardAttr", cardAttr);

                }
                if (detailUrl != "")
                {
                    sParaTemp.Add("detailUrl", detailUrl);
                }
                if (notifyUrl != "")
                {
                    sParaTemp.Add("notifyUrl", notifyUrl);
                }
                if (returnUrl != "")
                {
                    sParaTemp.Add("returnUrl", returnUrl);
                }

                LogUtil.Instance.WriteInfo(JsonUtil.stringify(sParaTemp)); // 记录日志

                ////

                Service allscore = new Service();
                string sHtmlText = "";

                /*
                        sParaTemp.Add("transAmt", transAmt);   //交易金额
                        sParaTemp.Add("subject", out_subject.Value.Trim());   //
                        sParaTemp.Add("body", out_body.Value.Trim());   //
                */
                sHtmlText = allscore.allscorePay(sParaTemp);


                Response.Write(sHtmlText);
            }
        }
    }
}